<?php
class model_module_navs extends database_mysql
{
	public function model_navs_get_com($Com=null)
    {   
		if(empty($Com))
		{
			$row = parent::mysql_fetch_all_rows("
				SELECT * FROM
					". prefix ."categories
					INNER JOIN ". prefix ."categories_lang 
					ON ". prefix ."categories.ID = ". prefix ."categories_lang.CatID
				WHERE
					". prefix ."categories.App = 'admin' AND
					". prefix ."categories.Define = 'com' AND
					". prefix ."categories.HorizontalMenu = 1 AND
					". prefix ."categories_lang.LangID = '".LANG."'
				ORDER BY ". prefix ."categories.Order ASC
			");
		}
		else{
		
			$Com = parent::mysql_check_string($Com);
			$row = parent::mysql_fetch_one_rows("
				SELECT * FROM
					". prefix ."categories
					INNER JOIN ". prefix ."categories_lang 
					ON ". prefix ."categories.ID = ". prefix ."categories_lang.CatID
				WHERE
					". prefix ."categories.App = 'admin' AND
					". prefix ."categories.Define = 'com' AND
					". prefix ."categories.Com = '".trim($Com)."' AND
					". prefix ."categories.HorizontalMenu = 1 AND
					". prefix ."categories_lang.LangID = '".LANG."'
				ORDER BY ". prefix ."categories.Order ASC
			");
		}

        parent::mysql_close_connection();
        
 		return $row;
    }
	
    public function model_navs_get_cat($id,$com=NULL)
    {
        $id =  parent::mysql_check_string($id);
		$str_com = empty($com)?NULL:" ". prefix ."categories.Com = '".$com."' AND ";
        $row = parent::mysql_fetch_all_rows("
            SELECT * FROM
                ". prefix ."categories
                INNER JOIN ". prefix ."categories_lang 
                ON ". prefix ."categories.ID = ". prefix ."categories_lang.CatID
            WHERE
                ". prefix ."categories.PID = '".$id."' AND
				". $str_com ."
                ". prefix ."categories_lang.LangID = '".LANG."'
            ORDER BY ". prefix ."categories.Order ASC
        ");
        
        parent::mysql_close_connection();
        
 		return $row;
    }

    public function model_navs_get_root()
    {
        $rows = parent::mysql_fetch_all_rows("
                  SELECT *
                  FROM prefix_categories cat, prefix_categories_lang catL
                  WHERE app='admin' and cat.ID = catL.catID
        ");

        parent::mysql_close_connection();
        return $rows;
    }
    
}